package com.woniuxy.controller;

import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.User;
import com.woniuxy.service.MyStudentService;
import com.woniuxy.utils.CodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/myStudent")
public class MyStudentController {

    @Autowired
    private MyStudentService myStudentService;

    /**
     * 根据场馆id查询该场馆有哪些学员
     * @param vid 场馆id
     * @return ResponseEntity
     */
    @GetMapping("/myStudents/{vid}")
    public ResponseEntity<List<User>> findMyStudentByVenueId(@PathVariable("vid") int vid){
        ResponseEntity<List<User>> usersResponseEntity = new ResponseEntity<>();
        System.out.println("学员：");
        System.out.println(vid);
        List<User> myStudentsByVenueId = myStudentService.findMyStudentsByVenueId(vid);
        return myStudentsByVenueId.size()<1 ? usersResponseEntity
                .setCode(CodeUtils.ERROR_CODE).setMsg("你还没有学员哦") : usersResponseEntity
                .setData(myStudentsByVenueId).setCode(CodeUtils.SUCCESS_CODE).setMsg("你的学员都在这了");
    }
}
